package com.ruipengkj.view;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.factory.ImageFactory;

public class RPSmaillToolBar extends JToolBar {

	private static final long serialVersionUID = 1L;
	private ImageIcon backgroundImageIcon = ImageFactory.loadImage(ImageFactory.SMAIL_TOOLBAR_BG);
	private TexturePaint paint = Util.createTexturePaint(backgroundImageIcon.getImage());
	private JLabel lab=new JLabel("        ");
	public RPSmaillToolBar() {
		this.setFloatable(false);// 设置工具栏不可移动
		this.setPreferredSize(new Dimension(0, 50));
	}
	
	public void setListData(Vector<JToggleButton> ves){
		this.removeAll();
		this.add(lab);
		ButtonGroup cbGroup=new ButtonGroup();
		if(ves!=null){
			JToggleButton jb=null;
			for(int i=0;i<ves.size();i++){
				jb=ves.get(i);
				this.add(ves.get(i));
				this.addSeparator();
				cbGroup.add(jb);
			}
		}
		this.updateUI();
	}

	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		// fill background.
		g2d.setPaint(paint);
		g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
		// //draw left image.
		// g2d.drawImage(backgroundLeftImage, 0, 0, null);
		// //draw right image.
		// int x = this.getWidth() - backgroundRightImage.getWidth(null);
		// int y = 0;
		// g2d.drawImage(backgroundRightImage, x, y, null);
	}
}
